package com.ruoyi.web.controller.app.im.app.controller;


import com.ruoyi.framework.web.exception.base.XResult;
import com.ruoyi.web.controller.app.im.app.service.AppCollectionService;
import com.ruoyi.web.core.base.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api(tags = "收藏模块",position = 2)
@RestController
@RequestMapping("/app/collection")
public class AppCollectionController extends BaseController {

    @Autowired
    private AppCollectionService appCollectionService;

    /**
     * 用户添加收藏
     * @param params
     * @return
     */
    @PostMapping("addCollection")
    @ApiOperation(notes = "addCollection", position = 1,value = "用户添加收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "content", value = "收藏内容", required = true, paramType = "query", dataType = "string"),
    })
    public XResult addCollection(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("收藏成功",appCollectionService.addCollection(params));
    }
    /**
     * 根据用户id查询收藏列表
     * @param params
     * @return
     */
    @PostMapping("findCollectionList")
    @ApiOperation(notes = "findCollectionList", position = 2,value = "根据用户id查询收藏列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult findCollectionList(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        startPage();
        return new XResult("查询成功",getDataTable(appCollectionService.findCollectionList(params.get("userId"))));
    }
    /**
     * 用户取消收藏
     * @param params
     * @return
     */
    @PostMapping("cancelCollection")
    @ApiOperation(notes = "cancelCollection", position = 3,value = "用户取消收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "collectionId", value = "收藏id", required = true, paramType = "query", dataType = "string"),
    })
    public XResult cancelCollection(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request) {
        return new XResult("取消收藏成功",appCollectionService.cancelCollection(params.get("collectionId")));
    }
}
